package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@JsonIgnoreProperties("handler")
public class Daily extends BaseDomain{
    //标题
    private String title;
    //日报文章摘要
    private String brief;
    //图片地址
    private String coverUrl;
    //发布时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date releaseTime;
    //资讯分类
    private Information information;

    //日报内容
    private DailyContent dailyContent;


    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("brief",brief);
        map.put("coverUrl",coverUrl);

        if(releaseTime!=null){
            map.put("releaseTime", DateUtil.formatDate(releaseTime));
        }
        if (information!=null){
            map.put("informationId",information.getId());
        }
        return JSONUtil.toJSONString(map);
    }

}